package com.hangxin.system.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Properties;
/**
 * 使用时请注意转码  new String(value.getBytes("iso8859-1"),"utf-8")
 * @author Administrator
 *
 */
public class ParameterUtil {
	
	
	private static Properties props = null;
	
	public static String getProperty(String key) throws UnsupportedEncodingException{
		
        loadProperties();
        
        if(props.getProperty(key)!=null)
        return new String(props.getProperty(key).getBytes("iso-8859-1"),"utf-8");
        
        return null;
    }
   
    public static void setProperty(String key,String value){
        loadProperties();
        props.setProperty(key,value);
    }
    
    public static Properties getProps(){
    	
    	loadProperties();
    	return props;
    }
    
    
    private static synchronized void loadProperties(){
    	
    	 if (props==null){
             props = new Properties();
             InputStream is = null;	
             try{

                 is = ParameterUtil.class.getClassLoader().getResourceAsStream("conf/parameter.properties");
                 System.out.println(is);
                 props.load(is);
             }catch(IOException e){
                 System.out.println("加载配置文件出错！");
             }finally{
                 if (is != null){
                     try{
                         is.close();
                     }catch(IOException e){
                         e.printStackTrace();
                     }
                 }
             }
         }
    }

}
